package com.example.webcomen.Controller;

import com.example.webcomen.Common.AjaxResult;
import com.example.webcomen.Model.GroupInfo;
import com.example.webcomen.Model.UserInfo;
import com.example.webcomen.Service.BaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    BaseInfoService baseInfoService;
    @GetMapping("/user/{userName}")
    public AjaxResult findUser(@PathVariable("userName")String name){
        List<UserInfo> userInfoList= baseInfoService.selectUsersByUserName(name);
        HashMap<String,Object> data=new HashMap<>();
        data.put("list",userInfoList);
        return AjaxResult.success(data);
    }
    @GetMapping("/group/{groupName}")
    public AjaxResult findGroup(@PathVariable("groupName")String name){
        List<GroupInfo> groupInfos= baseInfoService.selectGroupsByGroupName(name);
        HashMap<String,Object> data=new HashMap<>();
        data.put("list",groupInfos);
        return AjaxResult.success(data);
    }
}
